{extend name="common/base"/}
{block name="style"}
<link rel="stylesheet" href="{__STATIC__}/home/style/chapter-detail.css?v={$version}">
{/block}
{block name="title"}
<title>{:get_seo_str('chapter','chapter_title','',['chapterid'=>$id])}</title>	
{/block}
{block name="keywords"}
<meta name="keywords" content="{:get_seo_str('chapter','chapter_keywords','',['chapterid'=>$id])}"/>
<meta name="description" content="{:get_seo_str('chapter','chapter_description','',['chapterid'=>$id])}"/>
<meta property="og:type" content="novel"/>
<meta property="og:title" content="{$book.title|default=''}"/>
<meta property="og:description" content="{$book.remark|default=''}"/>
<meta property="og:image" content="{$book.cover|default=''}"/>
<meta property="og:novel:category" content="{:model('category')->where(['status' => 1, 'id' => $book['genre']])->value('name')}"/>
<meta property="og:novel:author" content="{$book.author|default=''}"/>
<meta property="og:novel:book_name" content="{$book.title|default=''}"/>
<meta property="og:novel:chapter_url" content="{:furl('chapter_detail',['id'=>$id,'bookid'=>$book['filename'] ? $book['filename'] : $book['id']])}"/>
<meta property="og:novel:chapter_title" content="{$chapter.title|default=''}"/>
<meta property="og:novel:author_link" content="{:url('author_detail',['id'=>$book['authorid']])}"/>
<meta property="og:novel:status" content="{$book.isfinish == 2 ? lang('finish') : lang('serialize')}"/>
{/block}
<!-- 主体 -->
{block name="body"}
{include file="common/header" nav='index' /}
<style>
</style>
{php}
$conConfig = get_system_config('content');
{/php}
{notempty name="book"}
    {php}
        if($book['genre']) {
            $genrename = model('category')->where(['status' => 1, 'id' => $book['genre']])->value('name');
            $genrelink = url('book_cates', ['id' => $book['genre']]);
        }
        if($book['subgenre']) {
            $subgenrename = model('category')->where(['status' => 1, 'id' => $book['subgenre']])->value('name');
            $subgenrelink = url('book_cates', ['id' => $book['genre']]);
        }
        if (!$conConfig['chapter_pages_content_open']) {
            $book_words_count = model('chapter')->where(['bookid' => $book['id'], 'status' => 1, ['verify', 'in', '0,1']])->sum('wordnum');
        }
    {/php}
{/notempty}
<div class="reader" id="page_reader">
    <div class="reader-crumb">
        <a href="{:url('/')}">首页</a><span></span>
        {notempty name="$genrename"}<a href="{$genrelink}">{$genrename}</a><span></span>{/notempty}   
        {notempty name="$subgenrename"}<a href="{$subgenrelink}">{$subgenrename}</a><span></span>{/notempty}
        {$book.title}
    </div>
    <style>
    .reader .reader-wrap .reader-r {
        width: 400px;
        background: #ffffff;
        border-radius: 12px;
        display: none;
        margin-left: 13px;
        position: relative;
    }
    .reader .reader-wrap .reader-r .reader-forum {
        padding: 36px 40px 40px;
        width: 400px;
    }
    .reader .reader-wrap .reader-r .close {
        width: 20px;
        height: 20px;
        cursor: pointer;
        position: absolute;
        right: 40px;
        top: 40px;
        z-index: 20;
    }
    .reader .reader-wrap .reader-r .forum-wrap {
        height: calc(100vh - 191px);
        overflow-y: auto;
        transition: height .3s;
        margin-right: -20px;
        padding-right: 20px;
    }
    .reader .reader-wrap .reader-r.fixed {
        position: fixed;
        margin-left: calc(var(--width) + 13px);
        top: 69px;
    }
    .reader .reader-wrap .reader-r.fixed .forum-wrap {
        height: calc(100vh - 191px)
    }
    {if isset($conConfig['chapter_refuse_collection_open']) && $conConfig['chapter_refuse_collection_open']}
    #chapter_content.unselectable {
        -webkit-touch-callout: none; /* iOS Safari */
        -webkit-user-select: none;   /* Safari */
        -moz-user-select: none;      /* Firefox */
        -ms-user-select: none;       /* IE/Edge */
        user-select: none;           /* Standard syntax */
    }
    {/if}
    </style>
    <div class="reader-wrap">
        <div class="reader-main">
            {if !$conConfig['chapter_pages_content_open']}            
            <div class="reader-top">
                <div class="bookimg"><a href="{:url('book_detail', ['id' => $book['filename'] ? $book['filename'] : $book['id']])}"><img src="{$book.cover|default=''}" alt="{$book.title}" onerror="this.src='{:get_file('')}'"><em></em></a></div>
                <div class="name">{$book.title}</div>
                <div class="au">{$book.author}</div>
                <div class="tags">
                    <span>{$genrename ? $genrename : '--'} <i>类型</i></span><i class="line"></i>
                    <span>{$book.create_time|default=''} <i>发布时间</i></span><i class="line"></i>
                    <span>{:wordCount($book_words_count)} <i>字数</i></span>
                </div>
                <div class="other">
                    <div class="b">版权所有 · 侵权必究</div>
                </div>
            </div>
            {/if}
            <div class="reader-content" id="Jcontent">
                <div class="reader-box">
                    <div class="title">
                        <div class="title_txtbox">{:get_full_chapter($chapter['title'], $chapter['chaps'])}</div>
                    </div>
                    <div class="bookinfo">
                        <span>本章字数：<i>{$chapter.wordnum}</i></span>
                        <span>更新时间：<i>{$chapter.update_time ? $chapter.update_time : $chapter.create_time|default=''}</i></span>
                    </div>
                    <div class="reader-line"></div>
                    <div class="content" id="chapter_content">
                        {if $conConfig['chapter_pages_content_open']}
                            {if isset($chapter['chapteraccess']) && $chapter['chapteraccess'] !== 1}
                                {if $chapter['chapteraccess'] == 0}
                                    <p data-id="0">未知错误</p>
                                {/if} 
                                {if $chapter['chapteraccess'] == -1}
                                    <p data-id="0">章节内容为空！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -2}
                                    <p data-id="0">未设置阅价格！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -8}
                                    <p data-id="0">参数错误！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -9}
                                    <p data-id="0">请登录后再阅读！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -10}
                                    <p data-id="0">用户不存在！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -11}
                                    <p data-id="0">没有阅读权限，请升级会员身份！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -12}
                                    <p data-id="0">非法用户身份！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -13}
                                    <p data-id="0">章节不存在！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -14}
                                    <p data-id="0">章节被禁止！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -15}
                                    <p data-id="0">章节内容为空！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -16}
                                    <p data-id="0">没有金币！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -17}
                                    <p data-id="0">不够本章节所需的金币数，请充值！</p>
                                {/if}
                                {if $chapter['chapteraccess'] == -19}
                                    <p data-id="0">请登录后再阅读！</p>
                                {/if}    
                            {else/}
                                {if isset($conConfig['chapter_refuse_collection_open']) && $conConfig['chapter_refuse_collection_open'] && is_array($content)}
                                    {foreach $content as $index => $text}
                                        <p data-id="{$index|raw}">{$text|raw}</p>
                                    {/foreach}
                                {else/}
                                    {$content|raw|default='暂无内容'}
                                {/if}
                            {/if}                            
                        {/if}
                    </div>
                    {if $conConfig['chapter_pages_content_open']}
                        <div class="btn-w">
                            <div class="btn-pagination">
                                <a href="{$front_url|default='javascript:void(0);'}">← 上一章</a>
                                <a href="{$after_url|default='javascript:void(0);'}">下一章 →</a>
                            </div>
                            {if get_system_config('power','report_open')}
                            <div class="btn-report"><a href="{:url('report')}" target="_blank"><i class="bi bi-shield-exclamation"></i>举报</a></div>
                            {/if}
                        </div>
                    {/if}
                </div>
            </div>
        </div>
        <div class="reader-r">
            <div class="reader-forum">
                <div class="close"><i class="bi bi-x-lg"></i></div>
                <div class="forum-wrap JforumWrap">
                    {if $conConfig['comment_open']}
                        {php} $targetType = 2; $target_id = $chapter['id']; {/php}
                        {include file="common/comment" /}
                    {/if}
                </div>
            </div>
        </div>
    </div>

    <div class="gpd-right-menu fixed" id="Jadom_panel">
        <div class="gpd-guidebar">
            <div class="tooltip-wrapper"><button class="list"><i class="bi bi-justify"></i><span class="text">目录</span></button></div>
            <div class="tooltip-wrapper"><button class="setting"><i class="bi bi-nut"></i><span class="text">设置</span></button></div>
            {if isset($conConfig['listen_book_open']) && $conConfig['listen_book_open']}
            <div class="tooltip-wrapper"><button class="listen"><i class="bi bi-music-note-list"></i><span class="text">听书</span></button></div>
            {/if}
            <div class="tooltip-wrapper"><button class="comment"><i class="bi bi-chat-dots"></i><span class="text">评论</span></button></div>
            <div class="tooltip-wrapper"><button class="like"><i class="bi bi-heart"></i><span class="text">点赞</span></button></div>
            <div class="tooltip-wrapper"><button class="bookshelf"><i class="bi bi-bag-plus"></i><span class="text">书架</span></button></div>
            <div class="tooltip-wrapper"><button class="addshelf btn_addshelf"><a href="{:url('book_detail', ['id' => $book['filename'] ? $book['filename'] : $book['id']])}"><i class="bi bi-book"></i><span class="text">书详情</span></a></button></div>            
        </div>
        <div class="gpd-toast-mask" style="display: none;"></div>
        <div class="gpd-reader-toast">
            <div class="gpd-wrap catalog gpd-flt-catalog" style="display: none;">
                <h3>章节目录</h3><div class="read-speed"><i style="width: 0%;"></i><font>阅读进度：0%</font></div>
                <div class="panel-list-wrap catalog-scroll-wrap" id="JcatalogListWrap">
                    <ul>
                        {notempty name="$chapterlist"}
                            {volist name="$chapterlist" id="v"}
                            <li data-chapterid="{$v.id}" {eq name="$v['id']" value="$id"} class="active"{/eq}><a href="{:furl('chapter_detail',['id'=>$v['id'],'bookid'=>$book['filename'] ? $book['filename'] : $book['id']])}"><span>{$v.title}</span></a></li>
                            {/volist}
                        {/notempty}
                    </ul>
                </div>
            </div>
            <div class="gpd-wrap gpd_flt_setting" data-pname="readerSetting" style="display: none;">
                <h3>阅读设置</h3>
                <div class="gpd-setLine gpd-setstyle">
                    <div class="gpd-setName">阅读背景</div>
                    <div class="gpd-setcon">
                        <a class="sbs-1 fontskin" href="javascript:void(0)" data-skin="theme1" alt="白色"></a>
                        <a class="sbs-2 fontskin" href="javascript:void(0)" data-skin="theme2" alt="蓝色"></a>
                        <a class="sbs-3 fontskin" href="javascript:void(0)" data-skin="theme3" alt="绿色"></a>
                        <a class="sbs-4 fontskin" href="javascript:void(0)" data-skin="theme4" alt="粉色"></a>
                        <a class="sbs-5 fontskin" href="javascript:void(0)" data-skin="theme5" alt="灰色"></a>
                        <a class="sbs-6 fontskin" href="javascript:void(0)" data-skin="theme6" alt="黄色"></a>
                        <a class="sbs-7 fontskin" href="javascript:void(0)" data-skin="theme7" alt="黑色"><i class="bi bi-brightness-high"></i></a>
                    </div>
                </div>
                <div class="gpd-setLine gpd-setfont">
                    <div class="gpd-setName">正文字体</div>
                    <div class="gpd-setcon">
                        <a href="javascript:void(0)" class="sbf-1 fontface" data-font="fontfamily1">宋体</a>
                        <a href="javascript:void(0)" class="sbf-2 fontface" data-font="fontfamily2">黑体</a>
                        <a href="javascript:void(0)" class="sbf-3 fontface" data-font="fontfamily3">雅黑</a>
                        <a href="javascript:void(0)" class="sbf-4 fontface" data-font="fontfamily4">楷体</a>
                    </div>
                </div>
                <div class="gpd-setLine gpd-setsize">
                    <div class="gpd-setName">字体大小</div>
                    <div class="gpd-setcon">
                        <div class="sbw-font">
                            <a data-size="0" class="font_size setfont" href="javascript:void(0)">A-</a>
                            <div class="nowfont" id="adom_reader_font_size"></div>
                            <a data-size="1" class="font_size setfont" href="javascript:void(0)">A+</a>
                        </div>
                    </div>
                </div>
            </div>
            {if isset($conConfig['listen_book_open']) && $conConfig['listen_book_open']}
            <style>
            :root {
                --primary: #3498db;
                --dark: #2c3e50;
                --light: #ecf0f1;
                --danger: #e74c3c;
                --border-radius: 12px;
                --transition: all 0.3s ease;
            }
            .tts-container {
                width: 100%;
            }

            .tts-container .tts-controls {
                display: flex;
                flex-direction: column;
                gap: 20px;
            }

            .tts-container .control-group {
                display: flex;
                flex-direction: column;
            }

            .tts-container .control-group label {
                display: flex;
                align-items: center;
                font-size: 18px;
                font-weight: 600;
                color: var(--dark);
                margin-bottom: 10px;
            }

            .tts-container .control-group label i {
                margin-right: 12px;
                color: var(--primary);
                font-size: 20px;
                width: 24px;
                text-align: center;
            }

            .tts-container select {
                padding: 15px;
                border: none;
                background-color: #f5f7fa;
                border-radius: 10px;
                font-size: 16px;
                color: var(--dark);
                border: 2px solid transparent;
                transition: var(--transition);
                appearance: none;
                background-image: url('data:image/svg+xml;utf8,<svg fill="%233498db" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
                background-repeat: no-repeat;
                background-position: right 15px center;
                background-size: 16px;
            }

            .tts-container select:focus {
                outline: none;
                border-color: var(--primary);
                background-color: white;
                box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.2);
            }

            .tts-container .control-group.button-group {
                flex-direction: row;
                flex-wrap: wrap;
                gap: 15px;
                margin-top: 10px;
            }

            .tts-container input[type="checkbox"] {
                appearance: none;
                -webkit-appearance: none;
                width: 18px;
                height: 18px;
                border: 2px solid #bbb;
                border-radius: 4px;
                outline: none;
                cursor: pointer;
                position: relative;
                transition: all 0.2s ease;
            }

            .tts-container input[type="checkbox"]:checked {
                background-color: #4285f4;
                border-color: #4285f4;
            }

            .tts-container input[type="checkbox"]:checked::after {
                content: '✓';
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                color: white;
                font-size: 14px;
                display: flex;
                justify-content: center;
                align-items: center;
            }

            .tts-container input[type="checkbox"]:hover {
                border-color: #aaa;
            }

            .tts-container input[type="checkbox"]:focus {
                box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
            }

            .tts-container .btn {                
                flex: 1;
                padding: 8px 10px;
                border: none;
                border-radius: 5px;
                font-size: 17px;
                font-weight: 600;
                cursor: pointer;
                transition: var(--transition);
                display: flex;
                justify-content: center;
                align-items: center;
                box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            }

            .tts-container .btn i {
                margin-right: 8px;
                font-size: 17px;
            }

            .tts-container .btn:hover {
                transform: translateY(-2px);
                box-shadow: 0 6px 12px rgba(0,0,0,0.15);
            }

            .tts-container .btn:active {
                transform: translateY(1px);
            }

            .tts-container .btn-play {
                background: var(--Linear, linear-gradient(159deg, #12C6FB 31.17%, #148AFF 72.66%));
                color: white;
            }

            .tts-container .btn-play:hover {
                background: linear-gradient(to right, #148AFF, #12C6FB);
            }

            .tts-container .btn-stop {
                background: linear-gradient(to right, var(--danger), #c0392b);
                color: white;
            }

            .tts-container .btn-stop:hover {
                background: linear-gradient(to right, #c0392b, #a93226);
            }

            .tts-container .btn.disabled {
                background: #7a7a7a;
                cursor: not-allowed;
                transform: none;
                box-shadow: none;
                opacity: 0.7;
            }

            .tts-container .btn.disabled:hover {
                transform: none;
                box-shadow: 0 4px 8px rgba(0,0,0,0.5);
            }

            .tts-highlight {
                background: rgba(72, 149, 239, 0.3) !important;
                box-shadow: 0 0 15px rgba(72, 149, 239, 0.5);
                animation: highlight-pulse 2s infinite;
            }
            
            @keyframes highlight-pulse {
                0% { box-shadow: 0 0 10px rgba(72, 149, 239, 0.5); }
                50% { box-shadow: 0 0 20px rgba(72, 149, 239, 0.8); }
                100% { box-shadow: 0 0 10px rgba(72, 149, 239, 0.5); }
            }
            </style>
            <div class="gpd-wrap gpd-listen-wrap" style="display:none">
                <h3>听书阅读</h3>
                <div class="tit">
                    <div class="tts-container">
                        <div class="tts-controls">
                            <div class="control-group">
                                <label for="tts-voices"><i class="bi bi-soundwave"></i> 语音</label>
                                <select id="tts-voices">
                                    <option value="0">Microsoft Xiaoxiao (中文)</option>
                                    <option value="1">Google US English</option>
                                    <option value="2">Amazon Amy (British)</option>
                                    <option value="3">Apple Samantha</option>
                                </select>
                            </div>
                            
                            <div class="control-group">
                                <label for="tts-rate"><i class="bi bi-sliders"></i> 语速</label>
                                <select id="tts-rate">
                                    <option value="0.5">慢速</option>
                                    <option value="0.8">稍慢</option>
                                    <option value="1.0" selected="">正常</option>
                                    <option value="1.3">稍快</option>
                                    <option value="1.6">快速</option>
                                </select>
                            </div>

                            <div class="control-group button-group">
                                <label><i class="bi bi-repeat"></i> 自动朗读</label>
                                <input type="checkbox" name="tts-read" id="tts-read" value="1">
                            </div>
                            
                            <div class="control-group button-group">
                                <button class="btn btn-play" id="ttsstart"><i class="bi bi-play"></i> 开始听书</button>
                                <button class="btn btn-stop" id="ttsstop"><i class="bi bi-stop"></i> 停止</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <script>
                window.TTSChapterContainer = '#Jcontent .content';
                window.TTSChapterContentOpen = parseInt("{$conConfig['chapter_pages_content_open']|default='0'}");
                window.TTSChapterNextPageObj = $('.btn-pagination a').eq(1);
                function feiniaoGetCookie() {
                    return $.getCookie("feiniaoTTS");
                }
                function feiniaoSetCookie(value) {
                    return $.setCookie("feiniaoTTS", value, 365);
                }
            </script>
            <script src="{__STATIC__}/home/js/tts.js?v={$version}"></script>
            {/if}
        </div>
    </div>
</div>
{/block}
<!-- 脚本 -->
{block name="script"}
<script>
$(window).on('load', function () {
    var chapter_id = '{$id}';
    var bookid = '{$bookid}';
    var report_open = parseInt("{:get_system_config('power','report_open')}");
    window.chapter_info = {};
    var info = {};
    var config = layui.data('feiniao').readconfig;
    var fontsizes = [16, 18, 20, 22, 24, 26, 28, 30];
    var isupperpage = false;    
    if(!config) {
        config = {
                "theme": "theme1",
                "fontfamily": "fontfamily1",
                "fontsize": 0,
            };
        //设置默认
        layui.data('feiniao', {
            key: 'readconfig',
            value: config
        });
    }
    //主题初始化
    $('.wrapper').addClass(config.theme);
    $('.gpd-setstyle .gpd-setcon').find('[data-skin="' + config.theme + '"]').addClass('active');
    //字体初始化
    $('.reader-box').attr('class', 'reader-box ' + config.fontfamily);
    $('.gpd-setfont .gpd-setcon').find('[data-font="' + config.fontfamily + '"]').addClass('active');
    //字号初始化
    $('.reader-box').css('font-size', fontsizes[parseInt(config.fontsize)] + 'px');
    $('#adom_reader_font_size').text(fontsizes[parseInt(config.fontsize)]);
    //打开
    $('.gpd-guidebar .tooltip-wrapper').on('click', function (obj, index) {
        if($(this).index() < 3) {
            $('.gpd-toast-mask').toggle();
            $(".gpd-reader-toast").toggle();
            $(".gpd-reader-toast .gpd-wrap:eq(" + $(this).index() + ")").toggle();
            if ($(this).index() === 0 && $(".gpd-reader-toast .gpd-wrap:eq(" + $(this).index() + ")").is(":visible")) {
                var offsettop = $('[data-chapterid="' + chapter_info.id + '"]').offset().top;
                var bordertop = parseInt($("#JcatalogListWrap").offset().top);
                $('#JcatalogListWrap').animate({
                    scrollTop: offsettop - bordertop
                }, 0);
            }
        }
    })
    //评论
    $('.comment').on('click', function (obj, index) {
        $('.reader').css('--side-width', '412px');
        $('.reader-r').show();
        $(this).parent().hide();
    })
    $('.reader .reader-wrap .reader-r .close').on('click', function (obj, index) {
        $('.reader').css('--side-width', '0px');
        $('.reader-r').hide();
        $('.tooltip-wrapper').show();
    })
    //书架
    $('.bookshelf').on('click', function (obj, index) {
        $.postApi("{:furl('v1/favorites', [], true, 'api')}", {bookid: bookid}, function(result) {
            layer.msg(result.msg);
            if(result.code == 0) {
                if(parseInt(chapter_info.fav) > 0) {
                    $('.bookshelf').find('i').attr('class', 'bi bi-bag-plus');
                } else {
                    $('.bookshelf').find('i').attr('class', 'bi bi-bag-plus-fill');                    
                }
            }
        });
    })
    //点赞
    $('.like').on('click', function (obj, index) {
        if(!isupperpage && parseInt(chapter_info.like) > 0) return layer.msg('已点过赞了');
        if(isupperpage && parseInt(info.like) > 0) return layer.msg('已点过赞了');
        $.postApi("{:furl('v1/like', [], true, 'api')}", {book_id: bookid, chapter_id: (isupperpage == true ? info.id : chapter_info.id)}, function(result) {
            layer.msg(result.msg);
            if(result.code == 0) {
                $('.like').find('i').attr('class','bi bi-heart-fill');
            }
        });
    })
    //关闭
    $('.gpd-toast-mask').on('click', function (obj, index) { 
        $('#JcatalogListWrap').animate({
            scrollTop: 0
        }, 0);
        $(this).hide();
        $(".gpd-reader-toast").toggle();
        $(".gpd-reader-toast .gpd-wrap").hide();        
    })
    //主题
    $('.gpd-setstyle .gpd-setcon a').on('click', function (obj, index) {
        var skin = $(this).data('skin');
        $('.fontskin').removeClass('active');
        $(this).addClass('active');
        $('.wrapper').attr('class', 'wrapper ' + skin);
        config.theme = skin;
        layui.data('feiniao', {
            key: 'readconfig',
            value: config
        });
    })
    //字体
    $('.fontface').on('click', function (obj, index) {
        var fontfamily = $(this).data('font');
        $('.fontface').removeClass('active');
        $(this).addClass('active');        
        config.fontfamily = fontfamily;
        layui.data('feiniao', {
            key: 'readconfig',
            value: config
        });
        $('.reader-box').attr('class', 'reader-box ' + config.fontfamily);
    })
    //字号
    $('.setfont').on('click', function (obj, index) {
        var size = $(this).data('size');
        if(parseInt(size) == 0) {
            if(parseInt(config.fontsize) <= 0) return layer.msg('已达最小值');
            config.fontsize--;         
        }
        if(parseInt(size) == 1) {
            if(parseInt(config.fontsize) >= 7) return layer.msg('已达最大值');
            config.fontsize++;           
        }
        layui.data('feiniao', {
            key: 'readconfig',
            value: config
        });
        $('.reader-box').css('font-size', fontsizes[config.fontsize] + 'px');
        $('#adom_reader_font_size').text(fontsizes[config.fontsize]);
    })
    //初始化
    {if !$conConfig['chapter_pages_content_open']}
        $.postApi("{:furl('v1/chapter', [], true, 'api')}", {limit: 1, id: chapter_id}, function(result) {
            if(result.code == 0) {
                chapter_info = result.data.data[0];
                chapter_id = chapter_info.front_chapter;
                $('.read-speed').find('i').css('width', chapter_info.speed + '%');
                $('.read-speed').find('font').text('阅读进度：' + chapter_info.speed + '%');
                $('.title_txtbox').html(chapter_info.title);
                $('.content').html(format_chapter(chapter_info.content));
                if(parseInt(chapter_info.like) > 0) {
                    $('.like').find('i').attr('class','bi bi-heart-fill');
                } else {
                    $('.like').find('i').attr('class','bi bi-heart');
                }
                if(parseInt(chapter_info.fav) > 0) {
                    $('.bookshelf').find('i').attr('class', 'bi bi-bag-plus-fill');
                } else {
                    $('.bookshelf').find('i').attr('class', 'bi bi-bag-plus');
                }            
            } else {
                layer.msg(result.msg);
            }
        });
    {else/}
        $.postApi("{:furl('v1/chapter', [], true, 'api')}", {limit: 1, id: chapter_id}, function(result) {
            if(result.code == 0) {
                const info = result.data.data[0];
                chapter_info = info;
                $('.read-speed').find('i').css('width', info.speed + '%');
                $('.read-speed').find('font').text('阅读进度：' + info.speed + '%');            
            }
        });
        {if isset($conConfig['chapter_refuse_collection_open']) && $conConfig['chapter_refuse_collection_open']}
            $.when(
                $.getScript("{__STATIC__}/home/js/protectionSystem.js?v={$version}"),
                $.Deferred(function(deferred) {
                    $(deferred.resolve);
                })
            ).done(function() {
                const protectionSystem = new ProtectionSystem();
                protectionSystem.init();
            }).fail(function(error) {
                console.error('脚本加载失败:', error);
            });
            document.addEventListener('keydown', function(e) {
                if (e.keyCode === 123 || (e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'i'))) {
                    e.preventDefault();
                }
            });
            document.onselectstart = function() { return false; };
            document.ondragstart = function() { return false; };
        {/if}
    {/if}
    //滚动
    {if !$conConfig['chapter_pages_content_open']}
        var isLoading = false;
        $(window).scroll(function() {
            if($(window).scrollTop() > 69) {
                $(".reader-r").addClass("fixed");
            } else {
                $(".reader-r").removeClass("fixed");
            }
            if($(window).scrollTop() <= 0 && !isLoading) {
                isLoading = true;
                isupperpage = true;
                upper_chapter();            
            } 
            var scrollTop = Math.ceil($(window).scrollTop());
            var height = Math.ceil($(window).height());
            var documentheight = parseInt($(document).height());
            if((scrollTop + height >= documentheight) && !isLoading) {
                isLoading = true;
                isupperpage = false;
                next_chapter();            
            }
        });

        //上一页    
        window.upper_chapter = function() {
            if(!chapter_id) {
                isLoading = false;
                return false;            
            }
            $.postApi("{:furl('v1/chapter', [], true, 'api')}", {limit: 1, id: chapter_id}, function(result) {
                isLoading = false;
                if(result.code == 0) {          
                    info = result.data.data[0];
                    chapter_id = info.front_chapter;
                    $('#JcatalogListWrap ul li').removeClass('active');
                    $('#JcatalogListWrap ul').find('[data-chapterid="' + info.id + '"]').addClass('active');
                    var html = `<div class="reader-box ${config.fontfamily}" style="font-size: ${fontsizes[config.fontsize]}px;">
                                    <div class="title">
                                        <div class="title_txtbox">${info.title}</div>
                                    </div>
                                    <div class="bookinfo">
                                        <span>本章字数：<i>${info.wordnum}</i></span>
                                        <span>更新时间：<i>${info.create_time}</i></span>
                                    </div>
                                    <div class="reader-line"></div>
                                    <div class="content">${format_chapter(info.content)}</div>
                                    <div class="btn-w">
                                    ${report_open > 0 ? '<div class="btn-report"><a href="{:url("report")}" target="_blank"><i class="bi bi-shield-exclamation"></i>举报</a></div>' : ''}
                                    </div>
                                </div>`;
                    $('#Jcontent').prepend(html);
                    if(parseInt(info.like) > 0) {
                        $('.like').find('i').attr('class','bi bi-heart-fill');
                    } else {
                        $('.like').find('i').attr('class','bi bi-heart');
                    }                
                } else {
                    layer.msg(result.msg);
                }
            });
        }
        //下一页
        window.next_chapter = function() {
            if(chapter_info && !chapter_info.after_chapter) {
                isLoading = false;
                return false;
            }
            if(chapter_info.after_chapter > 0) {
                $.postApi("{:furl('v1/chapter', [], true, 'api')}", {limit: 1, id: chapter_info.after_chapter}, function(result) {
                    isLoading = false;
                    if(result.code == 0) {
                        chapter_info = result.data.data[0];
                        $('.read-speed').find('i').css('width', chapter_info.speed + '%');
                        $('.read-speed').find('font').text('阅读进度：' + chapter_info.speed + '%');
                        $('#JcatalogListWrap ul li').removeClass('active');
                        $('#JcatalogListWrap ul').find('[data-chapterid="' + chapter_info.id + '"]').addClass('active');
                        var html = `<div class="reader-box ${config.fontfamily}" style="font-size: ${fontsizes[config.fontsize]}px;">
                                        <div class="title">
                                            <div class="title_txtbox">${chapter_info.title}</div>
                                        </div>
                                        <div class="bookinfo">
                                            <span>本章字数：<i>${chapter_info.wordnum}</i></span>
                                            <span>更新时间：<i>${chapter_info.create_time}</i></span>
                                        </div>
                                        <div class="reader-line"></div>
                                        <div class="content">${format_chapter(chapter_info.content)}</div>
                                        <div class="btn-w">
                                            ${report_open > 0 ? '<div class="btn-report"><a href="{:url("report")}" target="_blank"><i class="bi bi-shield-exclamation"></i>举报</a></div>' : ''}
                                        </div>
                                    </div>`;
                        $('#Jcontent').append(html);
                        if(parseInt(chapter_info.like) > 0) {
                            $('.like').find('i').attr('class','bi bi-heart-fill');
                        } else {
                            $('.like').find('i').attr('class','bi bi-heart');
                        }                    
                    } else {
                        layer.msg(result.msg);
                    }
                });            
            } else {
                isLoading = false;
            }
        }

        var format_chapter = function(chapter) {
            return '<p>' + chapter.split("<br>").join("</p><p>") + "</p>";
        };
    {/if}
});
</script>
{/block}
<!-- /脚本 -->